import test.Teacher;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-11-04
 * Time: 17:45
 */
public class Test2 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();

        //创建对象
        Teacher t1 = new Teacher("Tom","Core Java");
        Teacher t2 = new Teacher("John","Oracle");
        Teacher t3 = new Teacher("Susan","Oracle");
        Teacher t4 = new Teacher("Jerry","JDBC");
        Teacher t5 = new Teacher("Jim","Unix");
        Teacher t6 = new Teacher("Kevin","JSP");
        Teacher t7 = new Teacher("Lucy","JSP");
        //添加
        map.put(t1.getName(), t1.getCourse());
        map.put(t2.getName(), t2.getCourse());
        map.put(t3.getName(), t3.getCourse());
        map.put(t4.getName(), t4.getCourse());
        map.put(t5.getName(), t5.getCourse());
        map.put(t6.getName(), t6.getCourse());
        map.put(t7.getName(), t7.getCourse());
        System.out.println(map);
        System.out.println("--------------------------------------------------------------------");

        //新添加一个老师Allen教授JDBC
        Teacher t8 = new Teacher("Allen","JSP");
        map.put(t8.getName(), t8.getCourse());
        System.out.println(map);
        System.out.println("--------------------------------------------------------------------");

        //修改Lucy教授Core Java
        map.put("Lucy","Core Java");
        System.out.println(map);
        System.out.println("--------------------------------------------------------------------");

        //遍历
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String val = entry.getValue();
            System.out.println(key+"="+val);
        }
        System.out.println("--------------------------------------------------------------------");
        
        //教JSP的老师
        System.out.println("教JSP的老师: ");
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String val = entry.getValue();
            if(val.equals("JSP")){
                System.out.println(key+"="+val);
            }
        }
        System.out.println("--------------------------------------------------------------------");

        // 统计教授 CoreJava 和 JDBC 老师的人数
        int c1 = 0, c2 = 0;
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String val = entry.getValue();
            if(val.equals("Core Java"))
                c1++;
            if(val.equals("JDBC"))
                c2++;
        }
        System.out.println("教Core Java的人数为: "+c1+"\t教JDBC的人数为: "+c2);
    }
}
